import 'dart:convert';

import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:very_good_infinite_list/very_good_infinite_list.dart';
import 'package:http/http.dart' as http;

import '../provider/person_info.dart';

class Listview extends StatefulWidget {
  PersonInfo person;
  String selectvalue;
  List listTitle;
  List listValue;
  Listview(
      {super.key,
      required this.selectvalue,
      required this.person,
      required this.listTitle,
      required this.listValue});

  @override
  State<StatefulWidget> createState() => _Listview();
}

class _Listview extends State<Listview> {
  Future<void> showPic(PersonInfo person, String name) async {
    await fluent.showDialog<String>(
        barrierDismissible: true,
        context: context,
        builder: (context) => Material(
            child: SizedBox(
                width: 1000,
                child: Container(
                  color: Colors.white,
                  child: SizedBox(
                      height: 1000,
                      width: 1000,
                      child: IconButton(
                        iconSize: 1000,
                        icon: Image.network(
                          'https://lagelr.oss-cn-shenzhen.aliyuncs.com/lglr/$name/${widget.selectvalue}.jpg',
                          fit: BoxFit.fill,
                          height: 1000,
                          errorBuilder: (context, error, stackTrace) =>
                              Image.asset(
                            'image/no_pic.jpg',
                            fit: BoxFit.fill,
                            height: 1000,
                          ),
                        ),
                        onPressed: () {
                          Navigator.pop(context, '取消');
                        },
                      )),
                ))));
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
        child: InfiniteList(
            itemCount: widget.listTitle.length,
            onFetchData: () => {},
            separatorBuilder: (context, index) => const Divider(),
            itemBuilder: (context, index) {
              return Consumer<PersonInfo>(
                builder: (ctx, person, child) {
                  return ListTile(
                    dense: true,
                    onTap: () => showPic(person, widget.listTitle[index]),
                    title: Container(
                        margin: const EdgeInsets.only(top: 10, bottom: 10),
                        child: Row(
                          children: [
                            Expanded(
                              flex: 0,
                              child: Text(
                                widget.listTitle[index],
                                style: const TextStyle(fontSize: 18),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              child: Text(
                                widget.listValue[index],
                                textAlign: TextAlign.right,
                                style: const TextStyle(fontSize: 18),
                              ),
                            ),
                          ],
                        )),
                  );
                },
              );
            }));
  }
}
